package org.arch_learn.orm_starter.auto_config;

import org.arch_learn.flashboot.autoconfigure.*;
import org.arch_learn.flashboot.context.GlobalContext;
import org.arch_learn.orm_starter.annos.Mapper;
import org.arch_learn.orm_starter.config.XmlMapperBuilder;
import org.arch_learn.orm_starter.io.Resources;
import org.arch_learn.orm_starter.sqlSession.DefaultSqlSessionFactory;
import org.arch_learn.orm_starter.sqlSession.SqlSession;
import org.arch_learn.orm_starter.utils.ScanUtils;
import org.dom4j.DocumentException;

import javax.sql.DataSource;
import java.io.IOException;
import java.io.InputStream;
import java.util.Set;

@Configuration
@EnableConfigurationProperties(OrmConfigProperties.class)
@ConfigAfter(DataSourceAutoConfiguration.class)
@ConditionalOnBean(DataSource.class)
public class OrmAutoConfiguration {

    @Bean
    public DefaultSqlSessionFactory defaultSqlSessionFactory(DataSource dataSource, OrmConfigProperties ormConfigProperties) throws IOException, DocumentException {
        org.arch_learn.orm_starter.po.Configuration configuration = new org.arch_learn.orm_starter.po.Configuration(dataSource);
        DefaultSqlSessionFactory defaultSqlSessionFactory = new DefaultSqlSessionFactory(configuration, ormConfigProperties.getMapperLocation());
        defaultSqlSessionFactory.afterProperties();
        return defaultSqlSessionFactory;
    }

}
